package com.lyy.controller;

import com.lyy.entity.Product;
import com.lyy.service.ProductService;
import io.seata.core.exception.TransactionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Liangyaoyun
 */
@RestController
@RequestMapping("/api/v1/product")
public class ProductController {

    @Autowired
    public ProductService productService;

    @GetMapping("/selectProduct/{productId}")
    public Product selectProduct(@PathVariable("productId") Long productId) {
        return productService.selectById(productId);
    }

    @PostMapping("/updateStock/{productId}/{number}")
    public Long updateStock(@PathVariable Long productId,
                            @PathVariable Long number) throws TransactionException {

        return productService.updateStock(productId, number);
    }
}